package ua.org.enginer.controls
{
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import mx.controls.TextInput;
	
	[Event(name="defferedChange")]
	
	public class DefferedChangeTextInput extends TextInput
	{
		private var timer:Timer
		
		public static const DEFAULT_CHANGE_DELAY:int = 1000
		
		public function DefferedChangeTextInput()
		{
			super();
			timer = new Timer(DEFAULT_CHANGE_DELAY)
			timer.repeatCount = 1
			timer.addEventListener(TimerEvent.TIMER, onTimer)
			addEventListener(Event.CHANGE, onChange)
		}
		
		private function onTimer(event:TimerEvent):void 
		{
			dispatchEvent(new Event("defferedChange"))
		}
		
		private function onChange(event:Event):void 
		{
			if (timer.running) timer.reset()
			timer.start()
		}
		
		public function set changeDelay(value:int):void 
		{
			timer.delay = value
		}
		
		public function get changeDelay():int 
		{
			return timer.delay
		}
	}
}